import createAxiosClient from "@/app/utils/axiosRequest";
import ToastUtil from "@/app/utils/toastUtil";

export interface CollectionTreeItem {
  id: number;
  userId: number;
  parentId: number | null;
  name: string;
  description: string;
  icon: string;
  emoji: string;
  createdAt: string;
  updatedAt: string;
  children: CollectionTreeItem[];
}

/**
 * 获取集合树
 * @returns 集合树结构
 */
export async function getCollectionTree(): Promise<CollectionTreeItem[]> {
  try {
    const axiosInstance = createAxiosClient();
    const response = await axiosInstance.get('/app/collection/tree');
    
    if (response.data && response.data.status) {
      return response.data.data || [];
    } else {
      ToastUtil(response.data?.message || "获取目录树失败", "❌", "error");
      return [];
    }
  } catch (error: any) {
    ToastUtil(error.message || "获取目录树异常", "❌", "error");
    return [];
  }
} 